package com.concerneyes.mine.TabActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;

import com.concerneyes.R;
import com.concerneyes.mine.adapter.MyAccountAdapter;

import butterknife.ButterKnife;
import common.AbsActivity;
import util.ActivityUtil;
import util.ToastHelper;
import view.ListViewForScrollView;
import view.PopMenu;

/**
 * 我的账户
 */

public class MyAccount extends AbsActivity implements AdapterView.OnItemClickListener, View.OnClickListener, PopMenu.OnMenuItemClickListener {
    public final static int POP_MENU_ADD_ID = 100;
    public final static int POP_MENU_EDIT_ID = POP_MENU_ADD_ID + 1;
    private TextView mTvLeaveMoney;
    private ImageView iv_setbtn;
    /**
     * 余额说明
     */
    private TextView mLeaveMoney;
    private ScrollView mSvAccount;

    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.activity_account);
        String title = getIntent().getExtras().getString("title");
        setTitle(title);
        getRightText().setVisibility(View.VISIBLE);
        getRightText().setText(R.string.mingxi);
        initView();
    }

    @Override
    public void onRightTextAction(View v) {
        super.onRightTextAction(v);
        ActivityUtil.setIntent(this, MingXiActivity.class, null);
    }

    private void initView() {
        mTvLeaveMoney = (TextView) findViewById(R.id.tv_leave_money);
        mLeaveMoney = (TextView) findViewById(R.id.leave_money);
        iv_setbtn = (ImageView) findViewById(R.id.iv_setbtn);
        iv_setbtn.setOnClickListener(this);
        mSvAccount = (ScrollView) findViewById(R.id.sv_account);
        mTvLeaveMoney.setText("266.00");
        mLeaveMoney.setOnClickListener(this);
        mSvAccount.smoothScrollTo(0, 0);
    }


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        ToastHelper.getInstance()._toast("lv_return");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.leave_money:
//                ActivityUtil.setIntent(this,null,null);
                break;
            case R.id.iv_setbtn:
                super.onLeftTextAction(v);
                int arrayId = R.array.bank_cord1;
                int[] icons = new int[]{R.drawable.ic_add, R.drawable.ic_add};
                int menuId = POP_MENU_EDIT_ID;
                if (true) {
                    arrayId = R.array.bank_cord2;
                    icons = new int[]{R.drawable.wdqb_ico_add};
                    menuId = POP_MENU_ADD_ID;
                }else {
                    arrayId = R.array.bank_cord1;
                    icons = new int[]{R.drawable.wdqb_ico_write,R.drawable.wdqb_ico_delete};
                    menuId = POP_MENU_EDIT_ID;
                }
                String[] menuArray = getResources().getStringArray(arrayId);

                int width = this.getWindowManager().getDefaultDisplay().getWidth();
                int[] location = new int[2];
                iv_setbtn.getLocationOnScreen(location);
                int x = location[0];
                int y = location[1];
                int xoffset = -(width - x + iv_setbtn.getWidth() / 2);

                PopMenu menu = new PopMenu(this);
                menu.setOnMenuItemClickListener(this);
                menu.addItems(menuArray, icons);
                menu.showShadow();
                menu.setId(menuId);
                menu.showAsDropDown(iv_setbtn, xoffset, 20);
                break;
        }
    }

    @Override
    public void onMenuItemClick(int menuId, int position) {
        if (menuId == POP_MENU_ADD_ID) {
            ActivityUtil.setIntent(this, AddCardsActivity.class, null);
        } else if (menuId == POP_MENU_EDIT_ID) {

        }
    }
}
